package net.techwatch.poi;

import java.io.IOException;
import java.util.Iterator;

/**
 * @author wvandenberghe
 *
 * @param <T>
 */
public abstract class RowFileDataSource<T> implements Iterable<T> {

	/**
	 * 
	 */
	protected RowFileReader<T> reader;
	
	/**
	 * @param clazz
	 * @param configuration
	 * @param path
	 * @throws IOException
	 */
	public RowFileDataSource(Class<T> clazz, Configuration configuration, String path) throws IOException {
		super();
		Binder binder = new PrivateBinder();
		configuration.configure(binder);
		PrivateMatcher<T> privateMatcher = new PrivateMatcher<T>();
		privateMatcher.setBinder(binder);
		initReader(clazz, privateMatcher, path);
	}
	
	/**
	 * @param clazz
	 * @param matcher
	 * @param path
	 * @throws IOException
	 */
	protected abstract void initReader(Class<T> clazz, Matcher<T> matcher, String path)
	throws IOException;

	/* (non-Javadoc)
	 * @see java.lang.Iterable#iterator()
	 */
	public Iterator<T> iterator() {
		reader.reset();
		return reader;
	}

}